<html>
<head><meta charset="utf-8"><title>join on Iterator · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html">join on Iterator</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="203643505"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/203643505" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#203643505">(Jul 12 2020 at 13:17)</a>:</h4>
<p>Should we have <code>join</code> on iterator so that we could do the following and maybe have a bit of optimization without creating a <code>Vec</code> just to join an <code>Iterator</code>. Instead of <code>["hello", "world"].iter().collect::&lt;Vec&lt;_&gt;&gt;().join(" ")</code> one could do <code>["hello", "world"].iter().join(" ")</code>?</p>
<p>A rough idea on how it should look like:</p>
<div class="codehilite"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="nb">Iterator</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">join</span><span class="o">&lt;</span><span class="n">Separator</span><span class="o">&gt;</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">sep</span>: <span class="nc">Separator</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="o">&lt;</span><span class="p">[</span><span class="bp">Self</span>::<span class="n">Item</span><span class="p">]</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">Join</span><span class="o">&lt;</span><span class="n">Separator</span><span class="o">&gt;&gt;</span>::<span class="n">Output</span><span class="w"></span>
<span class="w">    </span><span class="k">where</span><span class="w"></span>
<span class="w">        </span><span class="p">[</span><span class="bp">Self</span>::<span class="n">Item</span><span class="p">]</span>: <span class="nc">Join</span><span class="o">&lt;</span><span class="n">Separator</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="c1">// ...</span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>I was surprised at first that I am not able to join into <code>String</code> from <code>Iterator</code>, I thought since <code>Iterator</code> may have a similar API to <code>slice</code> it would have <code>join</code>, I need to search to be able to know that I first need to get a <code>Vec&lt;String&gt;</code> to only be able to join, I wonder if it would be faster to join without first creating a <code>Vec</code>?</p>



<a name="203652802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/203652802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#203652802">(Jul 12 2020 at 17:31)</a>:</h4>
<p>This has been something I've wished for as well, but I think it'd be better to separate it from the existing slice::Join trait so it doesn't have to buffer up the components first at all</p>



<a name="203655321"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/203655321" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#203655321">(Jul 12 2020 at 18:36)</a>:</h4>
<p>FWIW, itertools does have this already: <a href="https://docs.rs/itertools/0.9.0/itertools/trait.Itertools.html#method.join">https://docs.rs/itertools/0.9.0/itertools/trait.Itertools.html#method.join</a></p>



<a name="203655330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/203655330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#203655330">(Jul 12 2020 at 18:37)</a>:</h4>
<p><code>format</code> and <code>format_with</code> are neat too</p>



<a name="203744922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/203744922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#203744922">(Jul 13 2020 at 17:34)</a>:</h4>
<p>Does it requires a FCP to move it to core? This does seemed like something quite common, not sure if it is good to keep it on itertools. Also, I wouldn't suggest the one on itertools, I don't think we should only be looking on <code>String</code>, <code>PathBuf</code> could be the output as well.</p>



<a name="203745381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/203745381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#203745381">(Jul 13 2020 at 17:38)</a>:</h4>
<p>As for me, <code>format</code> and <code>format_with</code> does not seemed to be as useful. I don't quite sure why I would need that, I think <code>dbg!()</code> could do that better.</p>



<a name="203752629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/203752629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#203752629">(Jul 13 2020 at 18:34)</a>:</h4>
<p><span class="user-mention" data-user-id="225422">@pickfire</span> I'm not on the libs team but generally single method additions only require a PR.</p>



<a name="203757438"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/203757438" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#203757438">(Jul 13 2020 at 19:10)</a>:</h4>
<p>Note that they're defined in different crates, <code>core::iter::Iterator</code> vs. <code>alloc::slice::Join</code></p>



<a name="203757533"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/203757533" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#203757533">(Jul 13 2020 at 19:11)</a>:</h4>
<p>I think coherence would prevent moving <code>Join</code> to <code>core</code>, since the impls need to be in <code>alloc</code> to refer to <code>Vec</code> and <code>String</code></p>



<a name="203768274"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/203768274" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#203768274">(Jul 13 2020 at 20:41)</a>:</h4>
<p>I found a related issue: <a href="https://github.com/rust-lang/rust/issues/22754">https://github.com/rust-lang/rust/issues/22754</a><br>
(<code>connect</code> was later deprecated / renamed to <code>join</code>)</p>



<a name="203816200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/203816200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#203816200">(Jul 14 2020 at 10:01)</a>:</h4>
<p>Maybe let me try adding it to itertools first and then send a PR to libs if that works, sounds like it needs an RFC from the comment.</p>



<a name="207067304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207067304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207067304">(Aug 16 2020 at 11:26)</a>:</h4>
<p>I did some tests on this, it generates the same output as assembly except it requires writing fewer types.</p>
<div class="codehilite"><pre><span></span><code><span class="cp">#![feature(slice_concat_trait)]</span><span class="w"></span>

<span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="n">iter</span>::<span class="n">FromIterator</span><span class="p">;</span><span class="w"></span>
<span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="n">slice</span>::<span class="n">Join</span><span class="p">;</span><span class="w"></span>

<span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">collect</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">B</span><span class="o">&gt;</span><span class="p">(</span><span class="n">iter</span>: <span class="nc">impl</span><span class="w"> </span><span class="nb">Iterator</span><span class="o">&lt;</span><span class="n">Item</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">T</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">B</span><span class="w"></span>
<span class="k">where</span><span class="w"></span>
<span class="w">    </span><span class="n">B</span>: <span class="nc">FromIterator</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">iter</span><span class="p">.</span><span class="n">collect</span><span class="p">()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">join</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">Separator</span><span class="o">&gt;</span><span class="p">(</span><span class="n">iter</span>: <span class="nc">impl</span><span class="w"> </span><span class="nb">Iterator</span><span class="o">&lt;</span><span class="n">Item</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">T</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="n">sep</span>: <span class="nc">Separator</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="o">&lt;</span><span class="p">[</span><span class="n">T</span><span class="p">]</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">Join</span><span class="o">&lt;</span><span class="n">Separator</span><span class="o">&gt;&gt;</span>::<span class="n">Output</span><span class="w"></span>
<span class="k">where</span><span class="w"></span>
<span class="w">    </span><span class="p">[</span><span class="n">T</span><span class="p">]</span>: <span class="nc">Join</span><span class="o">&lt;</span><span class="n">Separator</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="c1">// &lt;[S] as std::slice::Join&lt;&amp;str&gt;&gt;</span>
<span class="w">    </span><span class="c1">// &lt;[V] as std::slice::Join&lt;&amp;T&gt;&gt;</span>
<span class="w">    </span><span class="c1">// &lt;[V] as std::slice::Join&lt;&amp;[T]&gt;&gt;</span>
<span class="w">    </span><span class="n">Join</span>::<span class="n">join</span><span class="p">(</span><span class="n">iter</span><span class="p">.</span><span class="n">collect</span>::<span class="o">&lt;</span><span class="nb">Vec</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;&gt;</span><span class="p">().</span><span class="n">as_slice</span><span class="p">(),</span><span class="w"> </span><span class="n">sep</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="cp">#[inline(never)]</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">test_collect</span><span class="o">&lt;</span><span class="na">&#39;a</span><span class="o">&gt;</span><span class="p">(</span><span class="k">mut</span><span class="w"> </span><span class="n">iter</span>: <span class="nc">impl</span><span class="w"> </span><span class="nb">Iterator</span><span class="o">&lt;</span><span class="n">Item</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="na">&#39;a</span><span class="w"> </span><span class="kt">str</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">String</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">v</span>: <span class="nb">Vec</span><span class="o">&lt;</span><span class="n">_</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">iter</span><span class="p">.</span><span class="n">collect</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="n">v</span><span class="p">.</span><span class="n">as_slice</span><span class="p">().</span><span class="n">join</span><span class="p">(</span><span class="s">&quot; &quot;</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="cp">#[inline(never)]</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">test_join</span><span class="o">&lt;</span><span class="na">&#39;a</span><span class="o">&gt;</span><span class="p">(</span><span class="k">mut</span><span class="w"> </span><span class="n">iter</span>: <span class="nc">impl</span><span class="w"> </span><span class="nb">Iterator</span><span class="o">&lt;</span><span class="n">Item</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="na">&#39;a</span><span class="w"> </span><span class="kt">str</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">String</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">join</span><span class="p">(</span><span class="n">iter</span><span class="p">,</span><span class="w"> </span><span class="s">&quot; &quot;</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="cp">#[inline(never)]</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">test_manual</span><span class="o">&lt;</span><span class="na">&#39;a</span><span class="o">&gt;</span><span class="p">(</span><span class="k">mut</span><span class="w"> </span><span class="n">iter</span>: <span class="nc">impl</span><span class="w"> </span><span class="nb">Iterator</span><span class="o">&lt;</span><span class="n">Item</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="na">&#39;a</span><span class="w"> </span><span class="kt">str</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">String</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">sep</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot; &quot;</span><span class="p">;</span><span class="w"></span>

<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">buf</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">match</span><span class="w"> </span><span class="n">iter</span><span class="p">.</span><span class="n">next</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="nb">Some</span><span class="p">(</span><span class="n">buf</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="nb">String</span>::<span class="n">from</span><span class="p">(</span><span class="n">buf</span><span class="p">),</span><span class="w"></span>
<span class="w">        </span><span class="nb">None</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="nb">String</span>::<span class="n">new</span><span class="p">(),</span><span class="w"></span>
<span class="w">    </span><span class="p">};</span><span class="w"></span>
<span class="w">    </span><span class="n">iter</span><span class="p">.</span><span class="n">for_each</span><span class="p">(</span><span class="o">|</span><span class="n">s</span><span class="o">|</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">buf</span><span class="p">.</span><span class="n">push_str</span><span class="p">(</span><span class="n">sep</span><span class="p">);</span><span class="w"></span>
<span class="w">        </span><span class="n">buf</span><span class="p">.</span><span class="n">push_str</span><span class="p">(</span><span class="n">s</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">});</span><span class="w"></span>
<span class="w">    </span><span class="n">buf</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">assert_eq</span><span class="o">!</span><span class="p">(</span><span class="n">test_join</span><span class="p">([</span><span class="s">&quot;a&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;b&quot;</span><span class="p">].</span><span class="n">iter</span><span class="p">().</span><span class="n">copied</span><span class="p">()),</span><span class="w"> </span><span class="s">&quot;a b&quot;</span><span class="p">.</span><span class="n">to_string</span><span class="p">());</span><span class="w"></span>
<span class="w">    </span><span class="n">assert_eq</span><span class="o">!</span><span class="p">(</span><span class="n">test_collect</span><span class="p">([</span><span class="s">&quot;a&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;b&quot;</span><span class="p">].</span><span class="n">iter</span><span class="p">().</span><span class="n">copied</span><span class="p">()),</span><span class="w"> </span><span class="s">&quot;a b&quot;</span><span class="p">.</span><span class="n">to_string</span><span class="p">());</span><span class="w"></span>
<span class="w">    </span><span class="n">assert_eq</span><span class="o">!</span><span class="p">(</span><span class="n">test_manual</span><span class="p">([</span><span class="s">&quot;a&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;b&quot;</span><span class="p">].</span><span class="n">iter</span><span class="p">().</span><span class="n">copied</span><span class="p">()),</span><span class="w"> </span><span class="s">&quot;a b&quot;</span><span class="p">.</span><span class="n">to_string</span><span class="p">());</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>In which case, rather than writing</p>
<div class="codehilite"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">s</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">iter</span><span class="p">.</span><span class="n">collect</span>::<span class="o">&lt;</span><span class="nb">Vec</span><span class="o">&lt;</span><span class="n">_</span><span class="o">&gt;&gt;</span><span class="p">().</span><span class="n">join</span><span class="p">(</span><span class="s">&quot; &quot;</span><span class="p">);</span><span class="w"></span>
</code></pre></div>


<p>One can just write the following with the same generated assembly</p>
<div class="codehilite"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">s</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">iter</span><span class="p">.</span><span class="n">join</span><span class="p">(</span><span class="s">&quot; &quot;</span><span class="p">);</span><span class="w"></span>
</code></pre></div>


<p>Current limitations are that <code>Join</code> API is currently too limited, it implements quite less stuff, I wish it could use <code>AsRef</code> so that we don't need to do conversion on the iterator level.</p>
<p>I wonder if we could do optimization such as not needing to build a <code>Vec</code> first and directly construct the output but I haven't figure out a way that it could be faster yet, probably performance could improve. CC <span class="user-mention" data-user-id="209117">@lzutao</span> </p>
<p>However, this is different from the one provided in <code>itertools</code>, <code>itertools</code> already have <code>join</code> but that is only limited to <code>String</code> concatenation, this version is just <code>Iterator</code> with <code>Join</code>. What do you all think?</p>



<a name="207068301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207068301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207068301">(Aug 16 2020 at 11:53)</a>:</h4>
<p>I am not familiar with these APIs. You probably want to ping people like <span class="user-mention" data-user-id="143274">@Amanieu</span> .</p>



<a name="207071674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207071674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207071674">(Aug 16 2020 at 13:28)</a>:</h4>
<p><span class="user-mention" data-user-id="209117">@lzutao</span> No, I was discussing the performance. I was wondering if we could directly construct the output from join without having a separate vec first to make it faster.</p>



<a name="207109598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207109598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207109598">(Aug 17 2020 at 06:06)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> Do I need to do an RFC for this?</p>



<a name="207126094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207126094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207126094">(Aug 17 2020 at 10:09)</a>:</h4>
<p>You could look at Zip trait and its module to get more inspiration.<br>
Especially TrustedRandomAccess trait and its super trait ExactSizeIterator.</p>



<a name="207132333"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207132333" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207132333">(Aug 17 2020 at 11:34)</a>:</h4>
<p>I don't think an RFC is needed.</p>



<a name="207165756"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207165756" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207165756">(Aug 17 2020 at 16:33)</a>:</h4>
<p>I don't understand how is ExactSizeIterator is useful here since we need to get the length of the elements in the vector plus N times the length of the separator? I wonder if we can get the total length mentioned while copying the data so we don't need to iterate two times.</p>



<a name="207165871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207165871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207165871">(Aug 17 2020 at 16:34)</a>:</h4>
<p>By the way, <code>Box&lt;[T]&gt;</code>'s <code>FromIterator</code> looks way less efficient than <code>Vec&lt;T&gt;</code> when I looked into the generated code, I think I need to look into improving that while working on this.</p>



<a name="207167530"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207167530" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207167530">(Aug 17 2020 at 16:48)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> Does it need a tracking issue?</p>



<a name="207167586"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207167586" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207167586">(Aug 17 2020 at 16:49)</a>:</h4>
<p><code>Box&lt;[T]&gt;</code> just collects a <code>Vec&lt;T&gt;</code> and converts -- the only way that could be less efficient is in the implied shrink</p>



<a name="207167645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207167645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207167645">(Aug 17 2020 at 16:49)</a>:</h4>
<p>new unstable APIs always need a tracking issue, but I usually wait until I have a feeling whether it's going to be accepted at all</p>



<a name="207167654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207167654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207167654">(Aug 17 2020 at 16:49)</a>:</h4>
<p><span class="user-mention" data-user-id="138448">@cuviper</span> I understand, but the assembly generated is 2x more (96 -&gt; 184). <a href="https://godbolt.org/z/c9ffTT">https://godbolt.org/z/c9ffTT</a> I will be opening an issue for this.</p>



<a name="207167995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207167995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207167995">(Aug 17 2020 at 16:52)</a>:</h4>
<p>hmm, some panic handling for "Tried to shrink to a larger capacity"</p>



<a name="207168062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207168062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207168062">(Aug 17 2020 at 16:53)</a>:</h4>
<p>(which should be statically unreachable)</p>



<a name="207168071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207168071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207168071">(Aug 17 2020 at 16:53)</a>:</h4>
<p>Is that even possible?</p>



<a name="207168135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207168135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207168135">(Aug 17 2020 at 16:54)</a>:</h4>
<p>no, but I guess it isn't seeing that len&lt;=capacity</p>



<a name="207168255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207168255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207168255">(Aug 17 2020 at 16:55)</a>:</h4>
<p><span class="user-mention" data-user-id="138448">@cuviper</span> <a href="https://github.com/rust-lang/rust/issues/75636">https://github.com/rust-lang/rust/issues/75636</a></p>



<a name="207168397"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207168397" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207168397">(Aug 17 2020 at 16:56)</a>:</h4>
<p>maybe it should be guarded like <code>if self.len() &lt; self.capacity() { self.shrink_to_fit(); }</code> -- so the compiler may see that it's never greater</p>



<a name="207168595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207168595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207168595">(Aug 17 2020 at 16:58)</a>:</h4>
<p><span class="user-mention" data-user-id="225422">@pickfire</span> still, that should all be cold, not affecting real performance, except <em>maybe</em> icache pressure</p>



<a name="207168616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207168616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207168616">(Aug 17 2020 at 16:59)</a>:</h4>
<p>icache pressure?</p>



<a name="207168638"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207168638" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207168638">(Aug 17 2020 at 16:59)</a>:</h4>
<p>instruction cache memory</p>



<a name="207168693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207168693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207168693">(Aug 17 2020 at 16:59)</a>:</h4>
<p>pressure -&gt; unused instructions still taking up some space in that cache, leaving less room for useful stuff</p>



<a name="207168840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207168840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207168840">(Aug 17 2020 at 17:00)</a>:</h4>
<p>but that's very much something that should be measured before it is targeted for optimization</p>



<a name="207169718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207169718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207169718">(Aug 17 2020 at 17:09)</a>:</h4>
<p>This issue <a href="https://github.com/rust-lang/rust/issues/75638">https://github.com/rust-lang/rust/issues/75638</a></p>



<a name="207169821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207169821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207169821">(Aug 17 2020 at 17:10)</a>:</h4>
<p>Wow, my first time opening a tracking issue. Please let me work on the implementation, I want to try.</p>



<a name="207170018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207170018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207170018">(Aug 17 2020 at 17:12)</a>:</h4>
<p>oh, usually I do the implementation before a tracking issue, otherwise this is more of a request issue</p>



<a name="207170088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207170088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207170088">(Aug 17 2020 at 17:13)</a>:</h4>
<p>Ah, I thought it is the opposite.</p>



<a name="207170113"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207170113" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207170113">(Aug 17 2020 at 17:13)</a>:</h4>
<p>By the way, the POC is done so I don't see any issues doing the implementation.</p>



<a name="207170155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207170155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207170155">(Aug 17 2020 at 17:13)</a>:</h4>
<p>It's like a TODO issue for me, I just left it there, IIRC last time I just create a pull request without a tracking issue.</p>



<a name="207170272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207170272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207170272">(Aug 17 2020 at 17:15)</a>:</h4>
<p>The big question I still have is how you intend to reconcile this across different crates -- <code>core::iter::Iterator</code> can't reference <code>alloc::slice::Join</code>. The POC doesn't answer this at all.</p>



<a name="207172924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207172924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207172924">(Aug 17 2020 at 17:35)</a>:</h4>
<p>Oh, I didn't thought about that.</p>



<a name="207173060"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207173060" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207173060">(Aug 17 2020 at 17:36)</a>:</h4>
<p>Can we even implement it in <code>std::iter::Iterator</code>?</p>



<a name="207173092"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207173092" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207173092">(Aug 17 2020 at 17:36)</a>:</h4>
<p><code>std</code> is just a re-export</p>



<a name="207173135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207173135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207173135">(Aug 17 2020 at 17:36)</a>:</h4>
<p>I mentioned this before: <a href="#narrow/stream/219381-t-libs/topic/join.20on.20Iterator/near/203757438">https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/join.20on.20Iterator/near/203757438</a></p>



<a name="207500460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207500460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207500460">(Aug 20 2020 at 08:39)</a>:</h4>
<p>Ah, I forgot we cannot use <code>Vec</code> in <code>core</code>, <code>Vec</code> is needed to run <code>collect</code> before joining, do we need to do extension trait for this in alloc and reuse it in std?</p>



<a name="207500782"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207500782" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207500782">(Aug 20 2020 at 08:43)</a>:</h4>
<div class="codehilite"><pre><span></span><code>error[E0412]: cannot find type `Vec` in this scope
    --&gt; library/core/src/iter/traits/iterator.rs:1676:35
     |
1676 |         Join::join(self.collect::&lt;Vec&lt;Self::Item&gt;&gt;().as_slice(), sep)
     |                                   ^^^ not found in this scope

error[E0038]: the trait `iter::traits::iterator::Iterator` cannot be made into an object
    --&gt; library/core/src/iter/traits/iterator.rs:17:30
     |
17   | fn _assert_is_object_safe(_: &amp;dyn Iterator&lt;Item = ()&gt;) {}
     |                              ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `iter::traits::iterator::Iterator` cannot be made into an object
...
98   | pub trait Iterator {
     |           -------- this trait cannot be made into an object...
...
1672 |     fn join&lt;Separator&gt;(self, sep: Separator) -&gt; &lt;[Self::Item] as Join&lt;Separator&gt;&gt;::Output
     |        ---- ...because method `join` has generic type parameters
     |
     = help: consider moving `join` to another trait

error: aborting due to 2 previous errors
</code></pre></div>



<a name="207500939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207500939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207500939">(Aug 20 2020 at 08:44)</a>:</h4>
<p>I think we cannot put <code>join</code> into <code>Iterator</code> because the output is generic, maybe an extension trait? But I never seen any extension trait for <code>Iterator</code>.</p>



<a name="207501147"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207501147" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207501147">(Aug 20 2020 at 08:46)</a>:</h4>
<p>considering that we don't have collections in core, would it make sense to instead add <code>fn intersperse</code> to <code>Iterator</code>, so the example would be</p>
<div class="codehilite"><pre><span></span><code><span class="p">[</span><span class="s">&quot;hello&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;world&quot;</span><span class="p">].</span><span class="n">iter</span><span class="p">().</span><span class="n">intersperse</span><span class="p">(</span><span class="s">&quot; &quot;</span><span class="p">).</span><span class="n">fold</span><span class="p">(</span><span class="nb">String</span>::<span class="n">new</span><span class="p">(),</span><span class="w"> </span><span class="o">|</span><span class="n">s</span><span class="p">,</span><span class="w"> </span><span class="n">e</span><span class="o">|</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">s</span><span class="p">.</span><span class="n">append_str</span><span class="p">(</span><span class="n">e</span><span class="p">);</span><span class="w"> </span><span class="n">s</span><span class="w"> </span><span class="p">});</span><span class="w"></span>
</code></pre></div>



<a name="207501249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207501249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207501249">(Aug 20 2020 at 08:48)</a>:</h4>
<p><code>fn intersperse(self, e: Self::Item) -&gt; ... where Self::Item: Clone</code> and <code>fn intersperse_with&lt;F&gt;(self, f: F) -&gt; ... where F: FnMut() -&gt; Self::Item</code></p>



<a name="207501262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207501262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207501262">(Aug 20 2020 at 08:48)</a>:</h4>
<p><a href="https://hackage.haskell.org/package/base-4.14.0.0/docs/Data-List.html#v:intersperse">https://hackage.haskell.org/package/base-4.14.0.0/docs/Data-List.html#v:intersperse</a></p>



<a name="207501316"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207501316" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207501316">(Aug 20 2020 at 08:49)</a>:</h4>
<p>So it shouldn't be called <code>join</code> but instead <code>intersperse</code>?</p>



<a name="207501323"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207501323" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207501323">(Aug 20 2020 at 08:49)</a>:</h4>
<p>The term sounds complicated to me.</p>



<a name="207501418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207501418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207501418">(Aug 20 2020 at 08:50)</a>:</h4>
<p>But doesn't that only allows the same type of item to be the separator?</p>



<a name="207501450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207501450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207501450">(Aug 20 2020 at 08:50)</a>:</h4>
<p>Afaik, unlike <code>intersperse</code>, <code>join</code> is eager in other languages</p>



<a name="207501486"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207501486" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207501486">(Aug 20 2020 at 08:51)</a>:</h4>
<p>so it makes sense to take the name already used in haskell. We already mostly use that their names for Iterator methods</p>



<a name="207501491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207501491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207501491">(Aug 20 2020 at 08:51)</a>:</h4>
<p>Well, <code>collect</code> + <code>join</code> is eager too.</p>



<a name="207501509"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207501509" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207501509">(Aug 20 2020 at 08:51)</a>:</h4>
<p>exactly, and <code>intersperse</code> is lazy</p>



<a name="207501521"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207501521" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207501521">(Aug 20 2020 at 08:51)</a>:</h4>
<p>Yes, then <code>join</code> is the correct term.</p>



<a name="207501594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207501594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207501594">(Aug 20 2020 at 08:52)</a>:</h4>
<p>We seem to talk about slightly different things rn, sorry</p>



<a name="207501628"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207501628" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207501628">(Aug 20 2020 at 08:52)</a>:</h4>
<p>My concern is that we can't really implement <code>join</code> as part of <code>Iterator</code> as it requires allocations, is that right?</p>



<a name="207501630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207501630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207501630">(Aug 20 2020 at 08:52)</a>:</h4>
<p>Ah, I mean the process is supposed to be eager, not lazy. So it shouldn't be called <code>intersperse</code>.</p>



<a name="207501637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207501637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207501637">(Aug 20 2020 at 08:52)</a>:</h4>
<p>Yes.</p>



<a name="207501670"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207501670" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207501670">(Aug 20 2020 at 08:53)</a>:</h4>
<p>Unless we changed it like <code>collect</code>.</p>



<a name="207501704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207501704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207501704">(Aug 20 2020 at 08:53)</a>:</h4>
<p>So <code>intersperse</code> is a way to add this to core in a clean manner imo</p>



<a name="207501743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207501743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207501743">(Aug 20 2020 at 08:54)</a>:</h4>
<p>But I don't see what <code>intersperse</code> solve.</p>



<a name="207501796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207501796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207501796">(Aug 20 2020 at 08:54)</a>:</h4>
<p>what does <code>join</code> solve <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="207501800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207501800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207501800">(Aug 20 2020 at 08:54)</a>:</h4>
<p>It should allow joining with different type.</p>



<a name="207501816"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207501816" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207501816">(Aug 20 2020 at 08:54)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="nf">intersperse</span> <span class="sc">&#39;,&#39;</span> <span class="s">&quot;abcde&quot;</span>
</code></pre></div>


<p>That looks like the same type to me.</p>



<a name="207502007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502007">(Aug 20 2020 at 08:57)</a>:</h4>
<p>ah, hmm <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="207502199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502199">(Aug 20 2020 at 08:59)</a>:</h4>
<p>The other issue I faced is that the <code>join</code> I can think of have generics return.</p>



<a name="207502211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502211">(Aug 20 2020 at 08:59)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="k">fn</span> <span class="nf">join</span><span class="o">&lt;</span><span class="n">Separator</span><span class="o">&gt;</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">sep</span>: <span class="nc">Separator</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="o">&lt;</span><span class="p">[</span><span class="bp">Self</span>::<span class="n">Item</span><span class="p">]</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">Join</span><span class="o">&lt;</span><span class="n">Separator</span><span class="o">&gt;&gt;</span>::<span class="n">Output</span><span class="w"></span>
</code></pre></div>



<a name="207502321"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502321" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502321">(Aug 20 2020 at 09:01)</a>:</h4>
<p>But at the end, it probably still needs allocation.</p>



<a name="207502334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502334">(Aug 20 2020 at 09:01)</a>:</h4>
<p>So I don't think it is possible to put it into core.</p>



<a name="207502430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502430">(Aug 20 2020 at 09:02)</a>:</h4>
<p>wouldn't you want <code>&lt;Self::Item as Join&lt;Separater&gt;&gt;::Output</code>?</p>
<p>I am personally quite interested in adding <code>intersperse</code> to iterator as I needed a few times in the past and I think it can mostly replace join when dealing with iterators.</p>



<a name="207502454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502454">(Aug 20 2020 at 09:02)</a>:</h4>
<blockquote>
<p>wouldn't you want &lt;Self::Item as Join&lt;Separater&gt;&gt;::Output?</p>
</blockquote>
<p>Yes, I want that.</p>



<a name="207502464"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502464" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502464">(Aug 20 2020 at 09:03)</a>:</h4>
<p>But the tests does not want that.</p>



<a name="207502480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502480">(Aug 20 2020 at 09:03)</a>:</h4>
<p>I mean the compiler.</p>



<a name="207502518"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502518" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502518">(Aug 20 2020 at 09:03)</a>:</h4>
<p>but yeah, don't know how I feel about adding <code>join</code> to <code>Iterator</code>. I am also not part of <code>T-libs</code>so <span aria-label="shrug" class="emoji emoji-1f937" role="img" title="shrug">:shrug:</span></p>



<a name="207502525"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502525" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502525">(Aug 20 2020 at 09:03)</a>:</h4>
<p><span class="user-mention" data-user-id="216206">@lcnr</span> Can you do <code>intersperse</code> with different type?</p>



<a name="207502538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502538">(Aug 20 2020 at 09:03)</a>:</h4>
<p>I doubt it</p>



<a name="207502563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502563">(Aug 20 2020 at 09:04)</a>:</h4>
<p>Doubt? So no? Yes?</p>



<a name="207502587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502587">(Aug 20 2020 at 09:04)</a>:</h4>
<blockquote>
<p>But the tests does not want that.</p>
</blockquote>
<p>why</p>



<a name="207502604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502604">(Aug 20 2020 at 09:04)</a>:</h4>
<div class="codehilite"><pre><span></span><code>error[E0038]: the trait `iter::traits::iterator::Iterator` cannot be made into an object
    --&gt; library/core/src/iter/traits/iterator.rs:17:30
     |
17   | fn _assert_is_object_safe(_: &amp;dyn Iterator&lt;Item = ()&gt;) {}
     |                              ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `iter::traits::iterator::Iterator` cannot be made into an object
...
98   | pub trait Iterator {
     |           -------- this trait cannot be made into an object...
...
1672 |     fn join&lt;Separator&gt;(self, sep: Separator) -&gt; &lt;[Self::Item] as Join&lt;Separator&gt;&gt;::Output
     |        ---- ...because method `join` has generic type parameters
     |
     = help: consider moving `join` to another trait
</code></pre></div>



<a name="207502634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502634">(Aug 20 2020 at 09:04)</a>:</h4>
<p>you need <code>Self: Sized</code> on <code>join</code> in this case</p>



<a name="207502637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502637">(Aug 20 2020 at 09:04)</a>:</h4>
<p>I think</p>



<a name="207502661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502661">(Aug 20 2020 at 09:05)</a>:</h4>
<p>Oh, <code>collect</code> have that too.</p>



<a name="207502675"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502675" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502675">(Aug 20 2020 at 09:05)</a>:</h4>
<p>Nice, it worked.</p>



<a name="207502684"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502684" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502684">(Aug 20 2020 at 09:05)</a>:</h4>
<p>Only one thing left.</p>
<div class="codehilite"><pre><span></span><code>error[E0412]: cannot find type `Vec` in this scope
    --&gt; library/core/src/iter/traits/iterator.rs:1677:35
     |
1677 |         Join::join(self.collect::&lt;Vec&lt;Self::Item&gt;&gt;().as_slice(), sep)
     |                                   ^^^ not found in this scope

error: aborting due to previous error

For more information about this error, try `rustc --explain E0412`.
error: could not compile `core`.
</code></pre></div>



<a name="207502699"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502699" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502699">(Aug 20 2020 at 09:05)</a>:</h4>
<blockquote>
<p>Doubt? So no? Yes?</p>
</blockquote>
<p>intersperse with different types seems difficult to do cleanly</p>



<a name="207502723"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502723" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502723">(Aug 20 2020 at 09:05)</a>:</h4>
<p>at least I can't think of a good API rn</p>



<a name="207502783"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502783" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502783">(Aug 20 2020 at 09:06)</a>:</h4>
<p><code>Join</code> already have those.</p>



<a name="207502790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207502790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207502790">(Aug 20 2020 at 09:06)</a>:</h4>
<p>That's why I am just making use of the existing stuff to make this.</p>



<a name="207510596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207510596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207510596">(Aug 20 2020 at 11:02)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/75738">https://github.com/rust-lang/rust/pull/75738</a></p>



<a name="207516465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207516465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207516465">(Aug 20 2020 at 12:31)</a>:</h4>
<p>FWIW I think intersperse is a great idea even if it requires the same types</p>



<a name="207516531"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207516531" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207516531">(Aug 20 2020 at 12:32)</a>:</h4>
<p><code>s.split().intersperse (" ").collect()</code> is a lot easier to write than turbo fish for Vec</p>



<a name="207516543"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207516543" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207516543">(Aug 20 2020 at 12:32)</a>:</h4>
<p>And more efficient too I think since you only collect once</p>



<a name="207516784"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207516784" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207516784">(Aug 20 2020 at 12:35)</a>:</h4>
<p><code>intersperse</code> is already part of <code>Itertools</code>, it might make sense to promote it to std</p>



<a name="207517585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207517585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207517585">(Aug 20 2020 at 12:44)</a>:</h4>
<p>yeah, it is brilliant idea, but let's cc <span class="user-mention" data-user-id="139363">@bluss</span> on that</p>



<a name="207606840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207606840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207606840">(Aug 21 2020 at 07:33)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> The join I sent also collect once, <code>intersperse</code> looks useful but I see it as being very useful yet, at least not in my case.</p>



<a name="207606902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207606902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207606902">(Aug 21 2020 at 07:34)</a>:</h4>
<p>I only wish to not type <code>.collect::&lt;Vec&lt;_&gt;&gt;().join(sep)</code>, just <code>.join(sep)</code> would be more than good.</p>



<a name="207607613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207607613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207607613">(Aug 21 2020 at 07:45)</a>:</h4>
<p>the problem I see with join method on Iterator is that it requires allocation and an extension Trait.<br>
Where people use core only, they don't have a lazy iterator to loop over.</p>



<a name="207619036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207619036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207619036">(Aug 21 2020 at 10:18)</a>:</h4>
<p><span class="user-mention" data-user-id="225422">@pickfire</span> no, your suggestion collects twice: once to Vec and once again to join them all by a separator. So it allocates twice.</p>



<a name="207619058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207619058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207619058">(Aug 21 2020 at 10:18)</a>:</h4>
<p>It improves the ergnomics but not the behavior</p>



<a name="207620841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207620841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207620841">(Aug 21 2020 at 10:46)</a>:</h4>
<p>Why would join need an extension trait but not collect?</p>



<a name="207636991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207636991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207636991">(Aug 21 2020 at 13:58)</a>:</h4>
<p><span class="user-mention" data-user-id="211727">@Jonas Schievink</span> because <code>collect</code> just calls <code>FromIterator</code>, generic to any output. This <code>join</code> creates a <code>Vec</code> intermediate, so it can't be in <code>core</code>.</p>



<a name="207637230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207637230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207637230">(Aug 21 2020 at 14:00)</a>:</h4>
<p>IMO, this isn't worth it just to save a little typing. It would be more motivating if it could build dynamically to the final result, but that will probably need changes to <code>Join</code>.</p>



<a name="207637249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207637249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207637249">(Aug 21 2020 at 14:01)</a>:</h4>
<p>Isn't <code>join(sep)</code> just <code>intersperse(sep).collect()</code>?</p>



<a name="207637716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207637716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207637716">(Aug 21 2020 at 14:04)</a>:</h4>
<p>Ah, this one uses <code>slice::Join</code></p>



<a name="207637722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207637722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207637722">(Aug 21 2020 at 14:04)</a>:</h4>
<p>With itertools, yes, but then you also have <code>Itertools::join</code></p>



<a name="207638370"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207638370" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207638370">(Aug 21 2020 at 14:11)</a>:</h4>
<p>My take on this is that we should totally add <code>intersperse</code> and <code>format</code> from itertools to libcore, but nothing that requires allocation</p>



<a name="207639190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207639190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207639190">(Aug 21 2020 at 14:18)</a>:</h4>
<p>Yeah, I think changes to <code>Join</code> is required. <span class="user-mention" data-user-id="232545">@Joshua Nelson</span> I didn't noticed that. I am looking for a way to improve it, then all the users that currently do <code>.collect::&lt;Vec&lt;_&gt;&gt;().join()</code> needs to allocate twice then.</p>



<a name="207639433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207639433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207639433">(Aug 21 2020 at 14:20)</a>:</h4>
<p><span class="user-mention" data-user-id="211727">@Jonas Schievink</span> No, <code>Join</code> allows different types unlike <code>intersperse</code>.</p>



<a name="207639473"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207639473" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207639473">(Aug 21 2020 at 14:20)</a>:</h4>
<p><code>.collect::&lt;Vec&lt;_&gt;&gt;().join()</code> already allocates twice</p>



<a name="207639498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207639498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207639498">(Aug 21 2020 at 14:20)</a>:</h4>
<p>Well, all the users have to do this right now which is the easiest method.</p>



<a name="207639595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207639595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207639595">(Aug 21 2020 at 14:21)</a>:</h4>
<p><span class="user-mention silent" data-user-id="225422">pickfire</span> <a href="#narrow/stream/219381-t-libs/topic/join.20on.20Iterator/near/207639433">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink</span> No, <code>Join</code> allows different types unlike <code>intersperse</code>.</p>
</blockquote>
<p>ah, true</p>



<a name="207639704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207639704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207639704">(Aug 21 2020 at 14:22)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> Yes, indeed. What you said is correct. I am looking for a way to both improve the ergonomics and performance. But I don't know how to know how much to allocate at first without having the first <code>Vec</code>? How do you know how much to allocate for the final <code>Vec</code>?</p>



<a name="207642496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207642496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207642496">(Aug 21 2020 at 14:45)</a>:</h4>
<p>But if we used the <code>collect</code> approach, it would require may more effort than this, although it may gives more performance but everything needs to be added.</p>



<a name="207654160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207654160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207654160">(Aug 21 2020 at 16:22)</a>:</h4>
<p>that doesn't seem like a ton more effort though, it's <code>iter.join('a')</code> vs <code>iter.intersperse("a").collect()</code></p>



<a name="207654178"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207654178" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207654178">(Aug 21 2020 at 16:23)</a>:</h4>
<p>as long as there's an example for it it seems fine to me</p>



<a name="207677775"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207677775" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207677775">(Aug 21 2020 at 19:58)</a>:</h4>
<p>opened <a href="https://github.com/rust-lang/rust/pull/75784">https://github.com/rust-lang/rust/pull/75784</a> to add intersperse</p>



<a name="207711402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/207711402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#207711402">(Aug 22 2020 at 06:57)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> But you can't do <code>assert_eq!([[1, 2], [3, 4]].iter().copied().join(&amp;[0, 0][..]), [1, 2, 0, 0, 3, 4]);</code> with <code>intersperse</code>, if we want, we may need to add <code>intercalate</code> <a href="https://hackage.haskell.org/package/base-4.14.0.0/docs/Data-List.html#v:intercalate">https://hackage.haskell.org/package/base-4.14.0.0/docs/Data-List.html#v:intercalate</a></p>



<a name="208293510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/208293510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#208293510">(Aug 28 2020 at 00:48)</a>:</h4>
<p>I have a new idea today, how about adding an optional <code>Sep</code> to <code>FromIterator</code> so we could reuse <code>collect</code>.</p>



<a name="208293521"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/join%20on%20Iterator/near/208293521" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/join.20on.20Iterator.html#208293521">(Aug 28 2020 at 00:48)</a>:</h4>
<p>But still, it doesn't seemed to be good enough.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>